home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ecstr3.arc / STRNCPY.C < prev    next >
C/C++ Source or Header  |  1987-03-04  |  717b  |  29 lines

  1. /*  File   : strncpy.c
  2.     Author : Richard A. O'Keefe.
  3.     Updated: 20 April 1984
  4.     Defines: strncpy()
  5.  
  6.     strncpy(dst, src, n) copies up to n characters of src  to  dst.   It
  7.     will  pad  dst  on the right with NUL or truncate it as necessary to
  8.     ensure that n characters exactly are transferred.   It  returns  the
  9.     old value of dst as strcpy does.
  10. */
  11.  
  12. #include "strings.h"
  13.  
  14. char *strncpy(dst, src, n)
  15.     register char *dst, *src;
  16.     register int n;
  17.     {
  18.      char *save;
  19.  
  20.        for (save = dst;  --n >= 0; ) {
  21.            if (!(*dst++ = *src++)) {
  22.                while (--n >= 0) *dst++ = NUL;
  23.                return save;
  24.            }
  25.        }
  26.        return save;
  27.     }
  28.  
  29.